package com.example.demo.controller;


import com.example.demo.annotation.IgnoreAuth;
import com.example.demo.entity.pojo.Shangpinleixing;
import com.example.demo.entity.pojo.Shangpinxinxi;
import com.example.demo.service.IShangpinleixingService;
import com.example.demo.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品类型 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-01-09
 */
@RestController
@RequestMapping("/shangpinleixing")
public class ShangpinleixingController {
    @Autowired
    private IShangpinleixingService shangpinleixingService;
    @PostMapping("/sel")
    @IgnoreAuth
    public R sel(){
        List<Shangpinleixing> shangpinxinxis=shangpinleixingService.list();
        Map<String,Object> map=new HashMap<>();
        map.put("data",shangpinxinxis);
        map.put("msg","查询成功");
        map.put("code",200);
        return R.ok(map);
    }
    @PostMapping("/add")
    public R add(@RequestBody Shangpinleixing shangpinleixing){
        shangpinleixingService.save(shangpinleixing);
        Map<String,Object> map =  new HashMap<>();
        map.put("msg","添加成功");
        map.put("code",200);
        return R.ok(map);
    }
    @PostMapping("/update")
    public R update(@RequestBody Shangpinleixing shangpinleixing){
        shangpinleixingService.updateById(shangpinleixing);
        Map<String,Object> map =  new HashMap<>();
        map.put("msg","修改成功");
        map.put("code",200);
        return R.ok(map);
    }
    @PostMapping("/del")
    public R del(Long id){
        shangpinleixingService.removeById(id);
        Map<String,Object> map =  new HashMap<>();
        map.put("msg","删除成功");
        map.put("code",200);
        return R.ok(map);
    }
}
